package com.world.business.religious.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.world.business.religious.domain.ReligiousSect;
import com.world.business.religious.domain.query.ReligiousSectUpdateRequest;
import com.world.business.religious.domain.vo.ReligiousSectVO;
import com.world.business.religious.mapper.ReligiousSectMapper;
import com.world.business.religious.service.IReligiousSectService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 教派 服务实现类
 * </p>
 *
 * @author 邓驴
 * @since 2023-09-01
 */
@Service
public class ReligiousSectServiceImpl extends ServiceImpl<ReligiousSectMapper, ReligiousSect> implements IReligiousSectService {

    @Override
    public ReligiousSectVO get(Long id) {
        ReligiousSect religiousSect = this.baseMapper.selectById(id);
        return BeanUtil.copyProperties(religiousSect, ReligiousSectVO.class);
    }

    @Override
    public void update(ReligiousSectUpdateRequest request) {
        LambdaUpdateWrapper<ReligiousSect> updateWrapper = Wrappers.lambdaUpdate(ReligiousSect.class);
        updateWrapper.set(request.getParentId() != null, ReligiousSect::getParentId, request.getParentId());
        updateWrapper.set(StrUtil.isNotBlank(request.getName()), ReligiousSect::getName, request.getName());
        updateWrapper.set(StrUtil.isNotBlank(request.getDescription()), ReligiousSect::getDescription, request.getDescription());
        updateWrapper.set(StrUtil.isNotBlank(request.getAddress()), ReligiousSect::getAddress, request.getAddress());
        updateWrapper.set(request.getBeliefId() != null, ReligiousSect::getBeliefId, request.getBeliefId());
        updateWrapper.set(request.getMagicArts() != null, ReligiousSect::getMagicArts, request.getMagicArts());
        updateWrapper.set(request.getLawProtectMountain() != null, ReligiousSect::getLawProtectMountain, request.getLawProtectMountain());
        updateWrapper.set(StrUtil.isNotBlank(request.getPicUrl()), ReligiousSect::getPicUrl, request.getPicUrl());
        updateWrapper.set(StrUtil.isNotBlank(request.getVideoUrl()), ReligiousSect::getVideoUrl, request.getVideoUrl());
        updateWrapper.set(StrUtil.isNotBlank(request.getRemark()), ReligiousSect::getRemark, request.getRemark());
        updateWrapper.eq(ReligiousSect::getId, request.getId());
        this.baseMapper.update(null, updateWrapper);
    }

}
